package reflect;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 * 通过反射机制，反编译一个类的属性Field。
 */
public class ReflectTest06 {
    public static void main(String[] args) throws ClassNotFoundException {
        // 创建这个是为了拼接字符串
        StringBuffer stringBuffer = new StringBuffer();
//        Class<?> studentClass = Class.forName("bean.Student");
        Class<?> studentClass = Class.forName("java.lang.Integer");

        stringBuffer.append(Modifier.toString(studentClass.getModifiers()) + "class " + studentClass.getSimpleName() + " Student {\n")
        ;

        Field[] declaredFields = studentClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            stringBuffer.append("\t");
            stringBuffer.append(Modifier.toString(declaredField.getModifiers()));
            stringBuffer.append(" ");
            stringBuffer.append(declaredField.getType().getSimpleName());
            stringBuffer.append(declaredField.getName());
            stringBuffer.append(";\n");
        }

        stringBuffer.append("}");
        System.out.println(stringBuffer);
    }
}
